import React from 'react';
import Item, { IFormItemProps } from './Item'
import Radio, { RadioProps, RadioGroupProps } from 'antd/lib/radio';
import { RadioButtonProps } from 'antd/lib/radio/radioButton';


interface IRadioGroupProps extends RadioGroupProps, IFormItemProps {
	type: 'radio' | 'button',
	options: Array<{ label: string, value: string | number }>

}

export default class FormRadioGroup extends React.Component<IRadioGroupProps> {
	static defaultProps = { type: 'radio' }
	renderRadio = () => {
		let { options = [], type, ...resProps } = this.props;
		return (
			<Radio.Group {...resProps}>
				{options.map(option => {
					const { value, label } = option;
					return (
						type === 'button' ? <Radio.Button key={value} value={value}> {label} </Radio.Button> :
							<Radio key={value} value={value}> {label} </Radio>
					)
				})}
			</Radio.Group>
		)
	}
	render() {
		let { options, type, ...resProps } = this.props
		return (
			<Item {...this.props}
				render={() => (
					this.renderRadio()
				)} />
		)

	}
}